/// @tags: DP
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

constexpr int maxn = 33, mod = 1e9 + 9;

int m, n;
int f[3][3][3][3], g[maxn][maxn][maxn][maxn];
char s[maxn][maxn];
std::vector<std::pair<int, int> > dir, dir2;

inline int inc(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}

inline int dec(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}

int dfs(int x, int y, int x2, int y2) {
  if (s[x][y] != s[x2][y2]) return 0;
  if (x < 1 || x > m || y < 1 || y > n || x2 < 1 || x2 > m || y2 < 1 || y2 > n) return 0;
  if (g[x][y][x2][y2] != -1) return g[x][y][x2][y2];
  int res = 1;
  for (auto i : dir)
    for (auto j : dir2) {
      int dx = i.first, dy = i.second, dr = j.first, dc = j.second;
      res = inc(res, dfs(x + dx, y + dy, x2 + dr, y2 + dc));
    }
  return g[x][y][x2][y2] = res;
}

int solve(int x, int y, int x1, int x2) {
  if (f[x + 1][y + 1][x1 + 1][x2 + 1] != -1) return f[x + 1][y + 1][x1 + 1][x2 + 1];
  dir.clear(), dir2.clear();
  for (int i = -1; i <= 1; ++i)
    if (!i || i == x)
      for (int j = -1; j <= 1; ++j)
        if ((i || j) && (!j || j == y)) dir.emplace_back(i, j);
  for (int i = -1; i <= 1; ++i)
    if (!i || i == x1)
      for (int j = -1; j <= 1; ++j)
        if ((i || j) && (!j || j == x2)) dir2.emplace_back(i, j);
  memset(g, -1, sizeof(g));
  int res = 0;
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j)
      for (int r = 1; r <= m; ++r)
        for (int c = 1; c <= n; ++c) res = inc(res, dfs(i, j, r, c));
  f[x + 1][y + 1][x1 + 1][x2 + 1] = f[x1 + 1][x2 + 1][x + 1][y + 1] = res;
  f[-x + 1][-y + 1][-x1 + 1][-x2 + 1] = f[-x1 + 1][-x2 + 1][-x + 1][-y + 1] = res;
  return res;
}

int calc(int x, int y) {
  int res = 0;
  res = inc(res, solve(x, y, 1, 1));
  res = inc(res, solve(x, y, 1, -1));
  res = inc(res, solve(x, y, -1, 1));
  res = inc(res, solve(x, y, -1, -1));
  res = dec(res, solve(x, y, 1, 0));
  res = dec(res, solve(x, y, -1, 0));
  res = dec(res, solve(x, y, 0, 1));
  res = dec(res, solve(x, y, 0, -1));
  return res;
}

inline int main() {
  memset(f, -1, sizeof(f));
  cin >> m >> n;
  for (int i = 1; i <= m; ++i) cin >> (s[i] + 1);
  int ans = 0;
  ans = inc(ans, calc(1, 1));
  ans = inc(ans, calc(1, -1));
  ans = inc(ans, calc(-1, 1));
  ans = inc(ans, calc(-1, -1));
  ans = dec(ans, calc(1, 0));
  ans = dec(ans, calc(-1, 0));
  ans = dec(ans, calc(0, 1));
  ans = dec(ans, calc(0, -1));
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3713 [BJOI2017] 机动训练.in", "r", stdin);
  freopen("P3713 [BJOI2017] 机动训练.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
